
<template>
    <Div>      
        <H1>消费返利设置</H1>
            <Row>
                <Col span="3"><H2>联合创始人</H2></Col>
                <Col span="3"><Input v-model="costInput1"></Input></Col>
                <Col span="1"><H2>%</H2></Col>
                <Col span="3"><Button type="primary" @click="costOk1">确认</Button></Col>
            </Row>
            <br>
            <Row>
                <Col span="3"><H2>执行董事</H2></Col>
                <Col span="3"><Input v-model="costInput2"></Input></Col>
                <Col span="1"><H2>%</H2></Col>
                <Col span="3"><Button type="primary" @click="costOk2">确认</Button></Col>
            </Row>
            <br>
            <Row>
                <Col span="3"><H2>合伙人</H2></Col>
                <Col span="3"><Input v-model="costInput3"></Input></Col>
                <Col span="1"><H2>%</H2></Col>
                <Col span="3"><Button type="primary" @click="costOk3">确认</Button></Col>
            </Row>
            <br>
            <Row>
                <Col span="3"><H2>特约</H2></Col>
                <Col span="3"><Input v-model="costInput4"></Input></Col>
                <Col span="1"><H2>%</H2></Col>
                <Col span="3"><Button type="primary" @click="costOk4">确认</Button></Col>
            </Row>
        <H1>招商返利设置</H1>
            <Row>
                <Col span="3"><H2>联合创始人</H2></Col>
                <Col span="1"><H2>同级</H2></Col>
                <Col span="3"><Input v-model="bInput1"></Input></Col>
                <Col span="1"><H2>%</H2></Col>
                <Col span="1"><H2>下级</H2></Col>
                <Col span="3"><Input v-model="lowerInput1"></Input></Col>
                <Col span="1"><H2>%</H2></Col>
                <Col span="3"><Button type="primary" @click="bOk1">确认</Button></Col>
            </Row>
            <br>
            <Row>
                <Col span="3"><H2>执行董事</H2></Col>
                <Col span="1"><H2>同级</H2></Col>
                <Col span="3"><Input v-model="bInput2"></Input></Col>
                <Col span="1"><H2>%</H2></Col>
                <Col span="1"><H2>下级</H2></Col>
                <Col span="3"><Input v-model="lowerInput2"></Input></Col>
                <Col span="1"><H2>%</H2></Col>
                <Col span="3"><Button type="primary" @click="bOk2">确认</Button></Col>
            </Row>
            <br>
            <Row>
                <Col span="3"><H2>合伙人</H2></Col>
                <Col span="1"><H2>同级</H2></Col>
                <Col span="3"><Input v-model="bInput3"></Input></Col>
                <Col span="1"><H2>%</H2></Col>
                <Col span="1"><H2>下级</H2></Col>
                <Col span="3"><Input v-model="lowerInput3"></Input></Col>
                <Col span="1"><H2>%</H2></Col>
                <Col span="3"><Button type="primary" @click="bOk3">确认</Button></Col>
            </Row>
            <br>
            <Row>
                <Col span="3"><H2>特约</H2></Col>
                <Col span="1"><H2>同级</H2></Col>
                <Col span="3"><Input v-model="bInput4"></Input></Col>
                <Col span="1"><H2>%</H2></Col>
                <Col span="1"><H2>下级</H2></Col>
                <Col span="3"><Input v-model="lowerInput4"></Input></Col>
                <Col span="1"><H2>%</H2></Col>
                <Col span="3"><Button type="primary" @click="bOk4">确认</Button></Col>
            </Row>
        <H1>招商价格设置</H1>
            <Row>
                <Col span="3"><H2>联合创始人</H2></Col>
                <Col span="3"><Input v-model="bPriceInput1"></Input></Col>
                <Col span="3">&nbsp;<Button type="primary" @click="bPriceOk1">确认</Button></Col>
            </Row>
            <br>
            <Row>
                <Col span="3"><H2>执行董事</H2></Col>
                <Col span="3"><Input v-model="bPriceInput2"></Input></Col>
                <Col span="3">&nbsp;<Button type="primary" @click="bPriceOk2">确认</Button></Col>
            </Row>
            <br>
            <Row>
                <Col span="3"><H2>合伙人</H2></Col>
                <Col span="3"><Input v-model="bPriceInput3"></Input></Col>
                <Col span="3">&nbsp;<Button type="primary" @click="bPriceOk3">确认</Button></Col>
            </Row>
            <br>
            <Row>
                <Col span="3"><H2>特约</H2></Col>
                <Col span="3"><Input v-model="bPriceInput4"></Input></Col>      
                <Col span="3">&nbsp;<Button type="primary" @click="bPriceOk4">确认</Button></Col>
            </Row>
    </Div>
</template>
<script>
export default {
    data() {
        return {           
            costInput1:0,
            costInput2:0,
            costInput3:0,
            costInput4:0,
            bInput1:0,
            bInput2:0,
            bInput3:0,
            bInput4:0,
            lowerInput1:0,
            lowerInput2:0,
            lowerInput3:0,
            lowerInput4:0,
            bPriceInput1:0,
            bPriceInput2:0,
            bPriceInput3:0,
            bPriceInput4:0
        };
    },
    mounted() {
        let mid = localStorage.getItem("mid");
        if (mid == 'undefined' || mid == ''){
            alert("您还没有登陆");
            this.$router.push("admin");
            return;
        }
        if (mid.indexOf('3') < 0){
            alert("您没有权限");
            return;
        }
        this.getPercent();
    },
    methods: {
        getPercent(){
            let qs = require('qs');
            this.axios({
                method: "get",
                url: `${this.adminUrl}/getPercent`,
                data: qs.stringify({})
                }).then(response => {
                    if ((response.data.result == 200)) {                                                
                        this.setPercent(response.data.data);
                    }else{
                        alert("请求失败");
                    }
                }).catch(err =>{
                    console.log(err);
            }); 
        },
        setPercent(data){
            for (let i = 0; i < data.length; i++) {
                switch(data[i].type){
                    case '1':
                        this.costInput1 = data[i].num;
                    break;
                    case '2':
                        this.costInput2 = data[i].num;
                    break;
                    case '3':
                        this.costInput3 = data[i].num;
                    break;
                    case '4':
                        this.costInput4 = data[i].num;
                    break;
                    case '5':
                        this.bInput1 = data[i].num;
                    break;
                    case '6':
                        this.lowerInput1 = data[i].num;
                    break;
                    case '7':
                        this.bInput2 = data[i].num;
                    break;
                    case '8':
                        this.lowerInput2 = data[i].num;
                    break;
                    case '9':
                        this.bInput3 = data[i].num;
                    break;
                    case '10':
                        this.lowerInput3 = data[i].num;
                    break;
                    case '11':
                        this.bInput4 = data[i].num;
                    break;
                    case '12':
                        this.lowerInput4 = data[i].num;
                    break;
                    case '13':
                        this.bPriceInput1 = data[i].num;
                    break;
                    case '14':
                        this.bPriceInput2 = data[i].num;
                    break;
                    case '15':
                        this.bPriceInput3 = data[i].num;
                    break;
                    case '16':
                        this.bPriceInput4 = data[i].num;
                    break;
                }
            }
        },
        costOk1(){
            this.update(this.costInput1, 1);
        },
        costOk2(){
            this.update(this.costInput2, 2);
        },
        costOk3(){
            this.update(this.costInput3, 3);
        },
        costOk4(){
            this.update(this.costInput4, 4);
        },
        bOk1(){
            this.update(this.bInput1, 5);
            this.update(this.lowerInput1, 6);
        },
        bOk2(){
            this.update(this.bInput2, 7);
            this.update(this.lowerInput2, 8);
        },
        bOk3(){
            this.update(this.bInput3, 9);
            this.update(this.lowerInput3, 10);
        },
        bOk4(){
            this.update(this.bInput4, 11);
            this.update(this.lowerInput4, 12);
        },
        bPriceOk1(){
            this.update(this.bPriceInput1, 13);
        },
        bPriceOk2(){
            this.update(this.bPriceInput2, 14);
        },
        bPriceOk3(){
            this.update(this.bPriceInput3, 15);
        },
        bPriceOk4(){
            this.update(this.bPriceInput4, 16);
        },
        update(input, type){
            let qs = require('qs');
            this.axios({
                method: "patch",
                url: `${this.adminUrl}/updatePercent`,
                data: qs.stringify({num:input,type:type})
                }).then(response => {
                    if ((response.data.result == 200)) {                                                
                        this.getPercent();
                    }else{
                        alert("请求失败");
                    }
                }).catch(err =>{
                    console.log(err);
            }); 
        }
    }
};
</script>

   



<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
